<?php

class EasemobGroupLastMsgSeeder extends Seeder {

    public function run() 
    {
		// 1. get all the group_ids from the last_msg table
		// 2. update the last msg content for the sns_group
		$data = DB::select(DB::raw('select associate_id, content, max(`created_at`) from sns_msgs group by associate_id'));
		foreach ($data as $key => $obj) {
			if ($obj->associate_id) {
				$group = SNSGroup::find($obj->associate_id);
				if ($group) {
					$group->last_msg = $obj->content;
					$group->save();
				}
			}
		}
    }
}